package com.ace.explore.mobile.controller;

import com.ace.explore.mobile.dto.LoginResponse;
import com.ace.explore.users.model.UserBasicInfo;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Date;
import java.util.UUID;

/**
 * Created by zhangwanli on 2017/9/10.
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户", description = "/user")
public class UserController {
    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private RestTemplate restTemplate;

    @PostMapping("/login")
    @ApiOperation("登录")
    @ApiParam(name = "userName", value = "用户名")
    public LoginResponse login(@RequestParam String userName) {
        UserBasicInfo basicInfo = restTemplate.getForObject("http://users-service/basic-info/{userName}", UserBasicInfo.class, userName);
        logger.info("user-basic-info:{}", JSON.toJSONString(basicInfo));
        Boolean rs = restTemplate.getForObject("http://users-service/basic-info/test?name={name}&age={age}&birth={birth}", Boolean.class, "Bruce Lee", new Date().getTime(), 32);
        logger.info("rs={}", rs);
        LoginResponse result = new LoginResponse();
        result.setToken(UUID.randomUUID().toString());
        result.setLastLoginTime(new Date());
        return result;
    }

}
